package roboSoccer;

/**
 * This player behavior has the robot get behind the ball then push it in a
 * direction.
 * 
 * @author Ben Hopkins
 * 
 */
public class PbBallToPosition extends PlayerBehavior {

	Vector target;
	int progress; // 0 = go to side of ball

	// 1 = go behind ball
	// 2 = move forward

	public PbBallToPosition(RoboPlayer host, Vector target) {
		super(host, "balltoposition" + target.y + "," + target.x);
		this.target = target;
		progress = 0;
	}

	public boolean leaveState(GameState game) {
		return true;
	}

	public void update(GameState game) {
		// calculate targets
		Vector backTarget;
		backTarget = Vector.subtract(target, game.ball.position);
		backTarget.extend(30);
		backTarget = backTarget.add(target);

		switch (progress) {
		case 0:
			Vector sideTarget1 = Vector.subtract(target, game.ball.position)
					.oppositeVector();
			Vector sideTarget2 = Vector.subtract(target, game.ball.position)
					.oppositeVector();
			sideTarget1 = sideTarget1.truncate(30);
			sideTarget2 = sideTarget2.truncate(-30);
			Vector sideTarget = new Vector();
			if (sideTarget1.distance(host.position) < sideTarget2
					.distance(host.position))
				sideTarget = sideTarget1;
			else
				sideTarget = sideTarget2;

			host.controller.goToLocation(game, host, sideTarget, 5, 15, 5, 0);

			break;
		case 1:

			break;

		case 2:

			break;
		}
	}

}
